#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const int N=2e5+10;
#define INF 0x3f3f3f3f;
typedef long long int ll;
#define close(); std::ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
//----------------------------------------------------------------------------//

void solve()
{
	string s1,s2;
	cin>>s1>>s2;

	if(s1[0]==s2[0])
	{
		cout<<"YES"<<'\n';
		cout<<s1[0]<<'*'<<'\n';
		return;
	}

	if(s1[s1.size()-1]==s2[s2.size()-1])
	{
		cout<<"YES"<<'\n';
		cout<<"*"<<s1[s1.size()-1]<<'\n';
		return;
	}

	for(int i=0;i<s1.size()-1;i++)
	{
		string t=s1.substr(i,2);
		// t.push_back(s1[i]);
		// t.push_back(s1[i+1]);

		if(s2.find(t)!=s2.npos)
		{
			cout<<"YES"<<'\n';
			cout<<"*"<<t<<"*"<<'\n';
			return;
		}
	}
	cout<<"NO"<<'\n';



	
}

int main()
{
	close();
	int T; cin>>T;
	while (T--) solve();
	return 0;
}